<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php

class FileList extends FillBase
{

    
    public function obtainFileList($user_id, $parent_file_id = 0, $limit = 45, $start = 0){
        $list =  $this->getFilelist($user_id, $parent_file_id, $limit, $start);
        $data =  $this->filFillList($list);
        return $data;
    }

    
    public function getFilelist($user_id, $parent_file_id = 0, $limit = 45, $start = 0){
        $condition = "user_id=:user_id and is_deleted != 1 and parent_file_id=:parent_file_id";
        $params    = array(':user_id'=>$user_id, ':parent_file_id'=>$parent_file_id);
        $data = $this->getList($condition, $params, $limit, $start);
        return $data;
    }

    
    public function search($condition, $params, $limit = 30, $start = 0){
        $list = UserFile::model()->findAll(array(
                 'condition' =>$condition,
                 'params'    =>$params,
                 'limit'     =>$limit,
                 'offset'    =>$start,
        )
        );
        $data =  $this->filSearchFillList($list);
        return $data;
    }


    
    public function getFoderlist($user_id, $parent_file_id = 0){
        $condition = "user_id=:user_id and is_deleted != 1 and parent_file_id=:parent_file_id";
        $params    = array(':user_id'=>$user_id, ':parent_file_id'=>$parent_file_id);
        $data = $this->getList($condition, $params);
        return $data;
    }


    
    public function getFoderTree($userId){
        return UserFile::model()->getAllFolderJson($userId);
    }

    
    public function fileCount($user_id, $parent_file_id = 0){
        $condition = "user_id=:user_id and is_deleted != 1 and parent_file_id=:parent_file_id";
        $params    = array(':user_id'=>$user_id, ':parent_file_id'=>$parent_file_id);
        return $this->count($condition, $params);
    }


    
    public function navigation($user_id, $parent_file_id = 0){
        $nav = Array();
        if ($parent_file_id == 0){
            return $nav;
        }

        while ($parent_file_id != 0) {
            $condition = "user_id=:user_id and is_deleted != 1 and id=:id";
            $params    = array(':user_id'=>$user_id, ':id'=>$parent_file_id);
            $file = $this->find($condition, $params);
            if (empty($file) || $file['id'] == 0){
                return array_reverse($nav);
            }
            $data = Array();
            $data["id"]             = $file['id'];
            $data["fileName"]       = CUtils::utf8Unicode($file['file_name']);
            $data["parent_file_id"] = $file['parent_file_id'];

            array_push($nav, $data);
            $parent_file_id   = $file['parent_file_id'];
        }
        return array_reverse($nav);
    }
}
?>